<!DOCTYPE html>
<html>
	<head>
		<title>登录</title>
		{% include 'admin/common/header.html' %}
		<link rel="stylesheet" href="{{ url_for('static', filename='admin/css/other/login.css') }}" />
	</head>
	<body background="{{ url_for('static', filename='admin/images/background.svg') }}" style="background-size: cover;">
		<form class="layui-form" action="javascript:void(0);" autocomplete="off">
			<div class="layui-form-item">
				<img class="logo" src="{{ url_for('static', filename='admin/images/logo.png') }}" />
				<div class="title">Pyblog Manager</div>
				<div class="desc">
					欢 迎 您 访 问 Pyblog Manager 后 台 管 理 系 统
				</div>
			</div>
			<div class="layui-form-item">
				<input name="username" type="text" placeholder="账 户 :" lay-verify="required" hover class="layui-input" />
			</div>
			<div class="layui-form-item">
				<input name="password" type="password" placeholder="密 码 :" lay-verify="required" hover class="layui-input" />
			</div>
			<div class="layui-form-item">
				<input name="captcha" type="text" placeholder="验证码 :" lay-verify="required" hover class="code layui-input layui-input-inline"  />
				<a href="javascript:changeImg();"><img id="img" src="{{ url_for('admin.gen_captcha')}}" class="codeImage" /></a>
			</div>
			<div class="layui-form-item">
				<input type="checkbox" name="rememberme" title="记住密码" lay-skin="primary" checked>
			</div>
			<div class="layui-form-item">
				<button class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
					登 入
				</button>
			</div>
		</form>
		{% include 'admin/common/footer.html' %}
        <script>
			layui.use(['form', 'button', 'popup'], function() {
				var form = layui.form;
				var button = layui.button;
				var popup = layui.popup;

                form.on('submit(login)', function (data) {
                    let loader = layer.load();
                    let btn = button.load({elem: '.login'});
                    $.ajax({
                        data: data.field,
                        type: "post",
                        dataType: 'json',
                        success: function (result) {
                            layer.close(loader);
                            btn.stop(function () {
                                if (result.success) {
                                    popup.success(result.msg, function () {
                                        location.href = "{{ url_for('admin.manager') }}";
                                    })
                                } else {
                                    popup.failure(result.msg);
                                }
                            })
                        }
                    });
                })
			})
            function changeImg() {
                    document.getElementById("img").src = "{{ url_for('admin.gen_captcha')}}?r=" + Math.random();
            }
		</script>
	</body>
</html>
